package com.colorlight.cloud.complete.entity.enumerate;

import com.colorlight.cloud.common.exception.ParameterException;
import com.colorlight.cloud.common.model.ExceptionEnum;
import com.colorlight.cloud.gateway.api.message.constraint.basics.ienum.EnumTrans;
import com.colorlight.iot.proto.complete.entity.CompleteEntity;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

@Getter
public enum DehumidificationMode implements EnumTrans<CompleteEntity.DehumidificationMode, DehumidificationMode> {
    /**
     * 自动
     * 手动
     * 定时
     */
    DEHUMIDIFICATION_DEFAULT(CompleteEntity.DehumidificationMode.DEHUMIDIFICATION_DEFAULT),
    Automatic(CompleteEntity.DehumidificationMode.Automatic),
    Manual(CompleteEntity.DehumidificationMode.Manual),
    Timing(CompleteEntity.DehumidificationMode.Timing),
    ;

    private final Integer id;
    private final String name;
    private final CompleteEntity.DehumidificationMode dehumidificationMode;

    DehumidificationMode(CompleteEntity.DehumidificationMode dehumidificationMode) {
        this.id = dehumidificationMode.getNumber();
        this.name = dehumidificationMode.name();
        this.dehumidificationMode = dehumidificationMode;
    }

    /**
     * @param dehumidificationMode
     * @return 对应的类型
     */
    public static DehumidificationMode getScheduleTypeStruct(CompleteEntity.DehumidificationMode dehumidificationMode) {
        Objects.requireNonNull(dehumidificationMode, "dehumidificationMode can not be null.");
        return Arrays.stream(DehumidificationMode.values())
                .filter(e -> e.name.equals(dehumidificationMode.name()))
                .findFirst()
                .orElseThrow(() -> new ParameterException(ExceptionEnum.NOT_EXIST_ENUM));
    }

    @Override
    public CompleteEntity.DehumidificationMode toProto() {
        return this.dehumidificationMode;
    }

    @Override
    public DehumidificationMode formProto(CompleteEntity.DehumidificationMode dehumidificationMode) {
        return getScheduleTypeStruct(dehumidificationMode);
    }
}

